//
//  AFTableViewController.m
//  AFChat
//
//  Created by Void on 2018/6/22.
//  Copyright © 2018年 afei. All rights reserved.
//

#import "AFTableViewController.h"
#import "AFMenuItemCell.h"
#import "AFMenuItem.h"

static NSString * const cellID = @"MenuItemCell";
static NSString * const headerFooterID = @"headerFooterID";
@interface AFTableViewController ()

@end

@implementation AFTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 20)];
    
    [self.tableView registerClass:[AFMenuItemCell class] forCellReuseIdentifier:cellID];
//    [self.tableView registerClass:[UIView class] forHeaderFooterViewReuseIdentifier:headerFooterID];
    
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    AFMenuItemGrounp *group = [self.data objectAtIndex:section];
    return group.itemsCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AFMenuItemGrounp *group = [self.data objectAtIndex:indexPath.section];
    AFMenuItem *item = [group itemAtIndex:indexPath.row];
    AFMenuItemCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    [cell setMenuItem:item];
    
//    // cell分割线
//    if (item.type != LYCellItemTypeButton) {
//        indexPath.row == 0 ? [cell setTopLineStyle:LYCellLineStyleFill] : [cell setTopLineStyle:LYCellLineStyleNone];
//        indexPath.row == group.itemsCount - 1 ? [cell setBottomLineStyle:LYCellLineStyleFill] : [cell setBottomLineStyle:LYCellLineStyleDefault];
//    } else {
//        [cell setTopLineStyle:LYCellLineStyleNone];
//        [cell setBottomLineStyle:LYCellLineStyleNone];
//    }
    return cell;
}

/*
#pragma mark - UITableViewDelegate
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerFooterID];
    if (self.data && self.data.count > section) {
//        AFMenuItemGrounp *group = [self.data objectAtIndex:section];
//        [view setText:group.headerTitle];
    }
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerFooterID];
//    if (self.data && self.data.count > section) {
//        AFMenuItemGrounp *group = [self.data objectAtIndex:section];
//        [view setText:group.footerTitle];
//    }
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.data && self.data.count > indexPath.section) {
//        AFMenuItemGrounp *group = [self.data objectAtIndex:indexPath.section];
//        AFMenuItem *item = [group itemAtIndex:indexPath.row];
        return 44.0f;
    }
    return 0.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (self.data && self.data.count > section) {
//        AFMenuItemGrounp *group = [self.data objectAtIndex:section];
//        if (group.headerTitle == nil) {
//            return section == 0 ? 15.0f : 10.0f;
//        }
        return section == 0 ? 15.0f : 10.0f;
//        return [LYBaseHeaderFooterView getHeightForText:group.headerTitle];
    }
    return 10.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (self.data && self.data.count > section) {
//        AFMenuItemGrounp *group = [self.data objectAtIndex:section];
//        if (group.footerTitle == nil) {
//            return section == _data.count - 1 ? 30.0f : 10.0f;
//        }
        return section == _data.count - 1 ? 30.0f : 10.0f;
//        return [LYBaseHeaderFooterView getHeightForText:group.footerTitle];
    }
    return 10.0f;
}
 
 
*/


@end
